package karaoke.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import karaoke.DAOexcepcion.DAOExcepcion;
import karaoke.modelo.Sala;
import karaoke.negocio.GestionSala;

/**
 * Servlet implementation class SalaInsertarServlet
 */
@WebServlet("/SalaInsertarServlet")
public class SalaInsertarServlet extends javax.servlet.http.HttpServlet
		implements javax.servlet.Servlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public SalaInsertarServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub

		String nombre = request.getParameter("txtNombre");
		int capacidad = Integer.parseInt(request.getParameter("txtCapacidad"));
		String descripcion = request.getParameter("txtDescripcion");
		int idlocal = Integer.parseInt(request.getParameter("local"));

		Sala sala = new Sala();
		sala.setNombre_Sala(nombre);
		sala.setAforo_Sala(capacidad);
		sala.setDescripcion_Sala(descripcion);
		sala.setLocal_idLocal(idlocal);

		GestionSala c = new GestionSala();
		try {
			c.insertar(sala);
			response.sendRedirect(request.getContextPath()
					+ "/SalaBuscarServlet");
		} catch (DAOExcepcion e) {
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
	}

}
